﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using ControleRepresentante.Common;

namespace WebSite.Controllers
{
    public class HandleErrorAttribute : FilterAttribute, IExceptionFilter
    {
        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext.ExceptionHandled || filterContext.Exception.GetType() != ExceptionType)
            {
                return;
            }

            RouteValueDictionary routeValueDictionary = new RouteValueDictionary(new { controller = Controller, action = Action });
            filterContext.Result = new RedirectToRouteResult(routeValueDictionary);
            filterContext.ExceptionHandled = true;
            filterContext.HttpContext.Response.Clear();
        }

        public string Action { get; set; }
        public string Controller { get; set; }
        public Type ExceptionType { get; set; }
    }
}